package com.jml.队列.优先队列;

public class PriorityApp {

	public static void main(String[] args) {
		int arr[] = new int[50];
		int index = 0;
		index =insert(20,arr,index);
		index =insert(10,arr,index);
		index =insert(30,arr,index);
		index =insert(50,arr,index);
		index =insert(60,arr,index);
		index =insert(2,arr,index);
		index =insert(100,arr,index);
		index =insert(37,arr,index);
		index =insert(90,arr,index);
		index =insert(40,arr,index);
		for (int i = 0; i < index; i++) {
			System.out.println(arr[i]);
		}
		System.out.println();
	}

	private static int insert(int item, int[] arr,int index) {
		if(index==0){
			arr[0] = item;
			index++;
			return index;
		}else{
			int flag = -1;
			for (int i = index - 1; i >=0; i--) {
				if(arr[i]>item){
					arr[i+1]=arr[i];
					flag=i;
				}
			}
			if(flag == -1){
				arr[index]=item;
				index++;
			}else{
				arr[flag] = item;
				index++;
			}
			return index;
		}


	}

}